package reflect;

import java.lang.reflect.Constructor;

/**
 * 使用有参构造器实例化对象
 */
public class ReflectDemo03 {
    public static void main(String[] args) throws Exception{
        Person p = new Person("李四",22);
        System.out.println(p);

        //加载类对象
        Class cls = Class.forName("reflect.Person");

        //通过类对象获取无参构造器
//        Constructor constructor = cls.getConstructor();//Person()
        //Person(String,int)
        Constructor con = cls.getConstructor(String.class,int.class);
        //new Person("王五",33)
        Object obj = con.newInstance("王五",33);
        System.out.println(obj);
    }
}
